*********************************************************************
*** Against the Flow: Differentiating Between Public Opposition to the Immigration Stock and Flow
*** Yotam Margalit & Omer Solodoch 
*** Tel Aviv University, Political Science 
*** November 2020 
*** Replication do file 
********************************************************************* 

clear all
set mem 600m
set matsize 800	
set more off
set logtype text
set scheme s1color

*local directory "C:\[]" // set directory
local directory ""
cd "`directory'"


use data\flowstock_replication.dta


*** Data for figure 2a:
table treatment, c(mean approve_most semean approve_most n approve_most)

*** Data for figure 2b (+figure A2):
table treatment, c(mean approve_most semean approve_most n approve_most) by( female )
table treatment, c(mean approve_most semean approve_most n approve_most) by(higher_educ_R)
table treatment, c(mean approve_most semean approve_most n approve_most) by( poli )
table treatment, c(mean approve_most semean approve_most n approve_most) by( med_age_39 )
table treatment, c(mean approve_most semean approve_most n approve_most) by(party_d)


*** Table 2:
qui areg approve_most i.treatment##c.hisp_share i.female i.race i.education politic i.failed_screener, absorb(State) 
gen samp=e(sample)

areg approve_most i.treatment##i.USimm_parents i.female i.race i.education politic i.failed_screener if samp == 1, absorb(State) 
areg approve_most i.treatment##i.USimm_parents i.female i.education politic i.failed_screener if samp == 1 & white == 1, absorb(State) 

areg approve_most i.treatment##i.contact_d i.female i.race i.education politic i.failed_screener  if samp == 1, absorb(State) 
areg approve_most i.treatment##i.contact_d i.female  i.education politic i.failed_screener if samp == 1 & white == 1, absorb(State) 

areg approve_most i.treatment##c.hisp_share i.female i.race i.education politic i.failed_screener, absorb(State) 
areg approve_most i.treatment##c.hisp_share i.female  i.education politic i.failed_screener if samp == 1 & white == 1, absorb(State) 


*** Data for figure 3:
forvalue i = 1/10 { 
table treatment, c(mean stereotype_`i'Da semean stereotype_`i'Da n stereotype_`i'Da) row
}


*** Data for figure 4:
forvalue i = 1/3 {
table treatment, c(mean approve_most_`i' semean approve_most_`i' n approve_most_`i')
}

***********************************************************
**** robustness:
**** the stock premium across application reasons using OLS and controlling for demographics:
forvalue i = 1/3 {
reg approve_most_`i' treatment i.female i.race i.education 
}
***********************************************************

***********************************************************
**** footnote #21: the stock premium for economic immigrants is significantly larger than the (insignificant) stock premium for asylum seekers
reg approve_most_3 treatment i.female i.race i.education 
reg approve_most_2 treatment i.female i.race i.education  
test _b[treatment]==0.0288594
***********************************************************

*** Data for figure 5:
reg relevancy_2D i.treatment i.female i.age_cat_2 i.education politic i.poli i.failed_screener 
reg Lskills_Lfavor i.treatment i.female i.age_cat_2 i.education politic i.poli i.failed_screener 
reg relevancy_1D i.treatment i.female i.age_cat_2 i.education politic i.poli i.failed_screener 
reg age_economic i.treatment i.female i.age_cat_2 i.education politic i.poli i.failed_screener 

*** Data for figure 6:
table HHtreat, c(mean approve_most semean approve_most n approve_most)


************** Supporting information
*** install ebalance:
ssc install ebalance

** Table A1 (data for Column: "Lucid Sample")
tab age_cat_2
tab race
tab female
tab education

** Table A2
reg approve_most treatment age female i.education i.race 
***** entropy balancing
logit treatment age i.female i.higher_educ_R i.race i.poli
ebalance treatment age i.female i.higher_educ_R i.race i.poli, targets(1)
logit treatment age i.female i.higher_educ_R i.race i.poli [pweight=_webal] 
reg approve_most treatment age i.female i.higher_educ_R i.race i.poli [pweight=_webal] 
***** interactions
reg approve_most treatment##female age i.education i.race 
reg approve_most treatment##age_categories female i.education i.race 
reg approve_most treatment##i.higher_educ_R female age i.race 
reg approve_most treatment##i.race female age i.education 


clear
use data\flowstock_cjoint_replication.dta

**** Conjoint Experiment
*** Data for figure 7:
local inters stock_A_gender_d2 stock_A_education_d2 stock_A_education_d3 stock_A_language_d2 stock_A_language_d3 stock_A_language_d4 stock_A_country_d2 stock_A_country_d3 stock_A_country_d4 stock_A_country_d5 stock_A_country_d6 stock_A_country_d7 stock_A_country_d8 stock_A_country_d9 stock_A_country_d10 stock_A_profession_d2 stock_A_profession_d3 stock_A_profession_d4 stock_A_profession_d5 stock_A_profession_d6 stock_A_profession_d7 stock_A_profession_d8 stock_A_profession_d9 stock_A_profession_d10 stock_A_profession_d11 stock_A_experience_d2 stock_A_experience_d3 stock_A_experience_d4 stock_A_emplans_d2 stock_A_emplans_d3 stock_A_reason_d2 stock_A_reason_d3 stock_A_trips_d2 stock_A_trips_d3 stock_A_trips_d4 stock_A_trips_d5 
xtreg Qjoint_ i.A_gender i.A_education i.A_language i.A_country i.A_profession i.A_experience i.A_emplans i.A_reason i.A_trips `inters' if cjoint_treat != 2, fe vce(cluster rid)
test `inters'

*** Data for figure A3:
**Deportation:
local inters stock_A_gender_d2 stock_A_education_d2 stock_A_education_d3 stock_A_language_d2 stock_A_language_d3 stock_A_language_d4 stock_A_country_d2 stock_A_country_d3 stock_A_country_d4 stock_A_country_d5 stock_A_country_d6 stock_A_country_d7 stock_A_country_d8 stock_A_country_d9 stock_A_country_d10 stock_A_profession_d2 stock_A_profession_d3 stock_A_profession_d4 stock_A_profession_d5 stock_A_profession_d6 stock_A_profession_d7 stock_A_profession_d8 stock_A_profession_d9 stock_A_profession_d10 stock_A_profession_d11 stock_A_experience_d2 stock_A_experience_d3 stock_A_experience_d4 stock_A_emplans_d2 stock_A_emplans_d3 stock_A_reason_d2 stock_A_reason_d3 stock_A_trips_d2 stock_A_trips_d3 stock_A_trips_d4 stock_A_trips_d5 
xtreg Qjoint_ i.A_gender i.A_education i.A_language i.A_country i.A_profession i.A_experience i.A_emplans i.A_reason i.A_trips `inters' if cjoint_treat != 2, fe vce(cluster rid)
**No Deportation:
local inters stock_A_gender_d2 stock_A_education_d2 stock_A_education_d3 stock_A_language_d2 stock_A_language_d3 stock_A_language_d4 stock_A_country_d2 stock_A_country_d3 stock_A_country_d4 stock_A_country_d5 stock_A_country_d6 stock_A_country_d7 stock_A_country_d8 stock_A_country_d9 stock_A_country_d10 stock_A_profession_d2 stock_A_profession_d3 stock_A_profession_d4 stock_A_profession_d5 stock_A_profession_d6 stock_A_profession_d7 stock_A_profession_d8 stock_A_profession_d9 stock_A_profession_d10 stock_A_profession_d11 stock_A_experience_d2 stock_A_experience_d3 stock_A_experience_d4 stock_A_emplans_d2 stock_A_emplans_d3 stock_A_reason_d2 stock_A_reason_d3 stock_A_trips_d2 stock_A_trips_d3 stock_A_trips_d4 stock_A_trips_d5 
xtreg Qjoint_ i.A_gender i.A_education i.A_language i.A_country i.A_profession i.A_experience i.A_emplans i.A_reason i.A_trips `inters' if cjoint_treat != 3, fe vce(cluster rid)


clear
use data\flowstock_ANES.dta

*** Data for figure 8:
table VoteTrump, c(mean wall_D semean wall_D n wall_D)
table VoteTrump, c(mean unauth_stock1 semean unauth_stock1 n unauth_stock1)


